package com.css.resoft.p2pmonitor.dao.hbase;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.hadoop.hbase.thrift2.generated.TColumnValue;
import org.apache.hadoop.hbase.thrift2.generated.TGet;
import org.apache.hadoop.hbase.thrift2.generated.THBaseService;
import org.apache.hadoop.hbase.thrift2.generated.TResult;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import com.css.resoft.p2pmonitor.util.RowkeyUtil;
import com.css.resoft.p2pmonitor.vo.ContractVO;

public class ContractData {
	public static Map<String,String> getData(String orgCode,String dataDate,int xh) {
		String host = "39.107.112.148";
		int port = 9090;
		String table = "J0901";
		
		Map<String,String> contract = new HashMap<String,String>();
		
		byte[] rowkey = RowkeyUtil.getGetRowkey(orgCode, dataDate, xh);
		
		TTransport transport = new TSocket(host,port);
		TProtocol protocol = new TBinaryProtocol(transport);
		THBaseService.Iface client = new THBaseService.Client(protocol);
		try {
			transport.open();
			TGet get = new TGet();
			get.setRow(rowkey);
			
			TResult	result = client.get(ByteBuffer.wrap(table.getBytes()), get);
			
			if(result.row == null){
				System.out.println("dont get the data  return ");
				return contract;
			}
			
			for(TColumnValue columnValue : result.getColumnValues()){
				String key = new String(columnValue.getQualifier());
				String value = new String(columnValue.getValue());
				contract.put(key, value);
				// System.out.print("qualifier = " + new String(columnValue.getQualifier()));
				// System.out.println(" value = " + new String(columnValue.getValue())+" ");
			}
			
			transport.close();
			
		} catch (TException e) {
			e.printStackTrace();
		}finally{
			transport.close();
		}
		return contract;
	}
	
	public static List<ContractVO> scanData(String orgCode,String dataDate){
		List<ContractVO> contracts = null;
		
		return contracts;
	}
	
}
